package com.Test;

import com.dao.MybatisUtil;
import com.dao.SubjectDaol;

import com.entity.Subject;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TestSub {
    public static void main(String[] args) {
        TestSub test = new TestSub();
        //test.find();
        //test.add();
       // test.mel();
       // test.updt();
        test.limt();
    }

    public void find() {
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        SubjectDaol mapper = sqlSession.getMapper(SubjectDaol.class);
        List<Subject> sub = mapper.find();
        for (Subject subject : sub) {
            System.out.println(subject);
        }
        MybatisUtil.close(sqlSession);
    }

    public void add() {
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        SubjectDaol mapper = sqlSession.getMapper(SubjectDaol.class);
        int i = mapper.add(new Subject(100, 1, "天气预报"));
        System.out.println(i);
        MybatisUtil.commit(sqlSession);
        MybatisUtil.close(sqlSession);
    }
    public void mel(){
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        SubjectDaol mapper = sqlSession.getMapper(SubjectDaol.class);
        int i = mapper.del(new Subject(40));
        System.out.println(i);
        MybatisUtil.commit(sqlSession);
        MybatisUtil.close(sqlSession);
    }
    public void updt(){
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        SubjectDaol mapper = sqlSession.getMapper(SubjectDaol.class);
        int i = mapper.updt(new Subject("心理学10", 28));
        System.out.println(i);
        MybatisUtil.commit(sqlSession);
        MybatisUtil.close(sqlSession);
    }
    public void limt(){
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        SubjectDaol mapper = sqlSession.getMapper(SubjectDaol.class);
        List<Subject> sub = mapper.limt(4, 10);
        for (Subject subject : sub) {
            System.out.println(subject);
        }
        MybatisUtil.close(sqlSession);
    }
}
